<template>
    <div>
        <h1>学校名称：{{name | mySlice}}</h1>
        <h1>地址：{{address}}</h1>
        <button @click="showName">点我提示名称</button>
        <button @click="sendSchoolName">点我发送学校名称</button>
        <button @click="destroy">点我销毁School组件</button>
    </div>
</template>

<script>
import { myMixin1, myMixin2 } from '@/mixin'
export default {
    name: 'School',
    props:['name'],
    data() {
        return {
            // name: '奥克斯小学',
            address: '长沙'
        }
    },
    mixins: [myMixin1, myMixin2],
    methods:{
        sendSchoolName() {
            this.$emit('receiveSchoolName', this.name)
        },
        destroy() {
            console.log('destroy')
            this.$destroy()
        },
        receiveStuentName(name) {
            console.log("@@@receiveStuentName: " +name)
        }
    },
    mounted(){
        console.log('mounted')
        // this.$bus.$on('receiveStuentName', this.receiveStuentName)
        this.pubId = this.$pubsub.subscribe('receiveStuentName', (msgName, data) => {
            console.log('订阅 receiveStuentName 消息', msgName, data)
            console.log('##',this)
            this.receiveStuentName(data)
        })
    },
    beforeDestroy(){
        console.log('beforeDestroy...')
        // this.$bus.$off('receiveStuentName')
        this.$pubsub.unsubscribe(this.pubId)
        console.dir(this.$pubsub)
    }
}
</script>

<style scoped>

</style>